{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "51466c8d-8ce4-4b3d-be4e-18fdbeda5f53",
   "metadata": {},
   "source": [
    "# Dynamically Returning Directly\n",
    "\n",
    "In this example we will build a chat executor where the LLM can optionally decide to return the result of a tool call as the final answer. This is useful in cases where you have tools that can sometimes generate responses that are acceptable as final answers, and you want to use the LLM to determine when that is the case\n",
    "\n",
    "This examples builds off the base chat executor. It is highly recommended you learn about that executor before going through this notebook. You can find documentation for that example [here](./base.ipynb).\n",
    "\n",
    "Any modifications of that example are called below with **MODIFICATION**, so if you are looking for the differences you can just search for that.\n",
    "\n",
    "\n",
    "<div class=\"admonition tip\">\n",
    "    <p class=\"admonition-title\">Note</p>\n",
    "    <p>\n",
    "        In this how-to, we will create our agent from scratch to be transparent (but verbose). You can accomplish similar functionality using the <code>create_react_agent(model, tools=tool, interrupt_before=[\"agent\" | \"tools\"], interrupt_after=[\"agent\" | \"tools\"], checkpointer=checkpointer)</code> (<a href=\"https://langchain-ai.github.io/langgraph/reference/prebuilt/#create_react_agent\">API doc</a>) constructor. This may be more appropriate if you are used to LangChain’s <a href=\"https://python.langchain.com/v0.2/docs/how_to/agent_executor/#concepts\">AgentExecutor</a> class.\n",
    "    </p>\n",
    "</div>    "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7cbd446a-808f-4394-be92-d45ab818953c",
   "metadata": {},
   "source": [
    "## Setup\n",
    "\n",
    "First we need to install the packages required"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "af4ce0ba-7596-4e5f-8bf8-0b0bd6e62833",
   "metadata": {},
   "outputs": [],
   "source": ["%%capture --no-stderr\n%pip install --quiet -U langgraph langchain langchain_openai tavily-python"]
  },
  {
   "cell_type": "markdown",
   "id": "0abe11f4-62ed-4dc4-8875-3db21e260d1d",
   "metadata": {},
   "source": [
    "Next, we need to set API keys for OpenAI (the LLM we will use) and Tavily (the search tool we will use)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c903a1cf-2977-4e2d-ad7d-8b3946821d89",
   "metadata": {},
   "outputs": [],
   "source": ["import getpass\nimport os\n\nos.environ[\"OPENAI_API_KEY\"] = getpass.getpass(\"OpenAI API Key:\")\nos.environ[\"TAVILY_API_KEY\"] = getpass.getpass(\"Tavily API Key:\")"]
  },
  {
   "cell_type": "markdown",
   "id": "f0ed46a8-effe-4596-b0e1-a6a29ee16f5c",
   "metadata": {},
   "source": [
    "Optionally, we can set API key for [LangSmith tracing](https://smith.langchain.com/), which will give us best-in-class observability."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "95e25aec-7c9f-4a63-b143-225d0e9a79c3",
   "metadata": {},
   "outputs": [],
   "source": ["os.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\nos.environ[\"LANGCHAIN_API_KEY\"] = getpass.getpass(\"LangSmith API Key:\")"]
  },
  {
   "cell_type": "markdown",
   "id": "21ac643b-cb06-4724-a80c-2862ba4773f1",
   "metadata": {},
   "source": [
    "## Set up the tools\n",
    "\n",
    "We will first define the tools we want to use.\n",
    "For this simple example, we will use a built-in search tool via Tavily.\n",
    "However, it is really easy to create your own tools - see documentation [here](https://python.langchain.com/v0.2/docs/how_to/custom_tools) on how to do that.\n",
    "\n",
    "**MODIFICATION**\n",
    "\n",
    "We overwrite the default schema of the input tool to have an additional parameter for returning directly."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4a1b9990-3b11-4a51-bd51-76117afd38b9",
   "metadata": {},
   "outputs": [],
   "source": ["from langchain_core.pydantic_v1 import BaseModel, Field\n\n\nclass SearchTool(BaseModel):\n    \"\"\"Look up things online, optionally returning directly\"\"\"\n\n    query: str = Field(description=\"query to look up online\")\n    return_direct: bool = Field(\n        description=\"Whether or the result of this should be returned directly to the user without you seeing what it is\",\n        default=False,\n    )"]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d7ef57dd-5d6e-4ad3-9377-a92201c1310e",
   "metadata": {},
   "outputs": [],
   "source": ["from langchain_community.tools.tavily_search import TavilySearchResults\n\nsearch_tool = TavilySearchResults(max_results=1, args_schema=SearchTool)\ntools = [search_tool]"]
  },
  {
   "cell_type": "markdown",
   "id": "01885785-b71a-44d1-b1d6-7b5b14d53b58",
   "metadata": {},
   "source": [
    "We can now wrap these tools in a simple ToolExecutor.\n",
    "This is a real simple class that takes in a ToolInvocation and calls that tool, returning the output.\n",
    "A ToolInvocation is any class with `tool` and `tool_input` attribute.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5cf3331e-ccb3-41c8-aeb9-a840a94d41e7",
   "metadata": {},
   "outputs": [],
   "source": ["from langgraph.prebuilt import ToolExecutor\n\ntool_executor = ToolExecutor(tools)"]
  },
  {
   "cell_type": "markdown",
   "id": "5497ed70-fce3-47f1-9cad-46f912bad6a5",
   "metadata": {},
   "source": [
    "## Set up the model\n",
    "\n",
    "Now we need to load the chat model we want to use.\n",
    "Importantly, this should satisfy two criteria:\n",
    "\n",
    "1. It should work with messages. We will represent all agent state in the form of messages, so it needs to be able to work well with them.\n",
    "2. It should work with OpenAI function calling. This means it should either be an OpenAI model or a model that exposes a similar interface.\n",
    "\n",
    "Note: these model requirements are not requirements for using LangGraph - they are just requirements for this one example.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "892b54b9-75f0-4804-9ed0-88b5e5532989",
   "metadata": {},
   "outputs": [],
   "source": ["from langchain_openai import ChatOpenAI\n\n# We will set streaming=True so that we can stream tokens\n# See the streaming section for more information on this.\nmodel = ChatOpenAI(temperature=0, streaming=True)"]
  },
  {
   "cell_type": "markdown",
   "id": "a77995c0-bae2-4cee-a036-8688a90f05b9",
   "metadata": {},
   "source": [
    "\n",
    "After we've done this, we should make sure the model knows that it has these tools available to call.\n",
    "We can do this by converting the LangChain tools into the format for OpenAI function calling, and then bind them to the model class.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "cd3cbae5-d92c-4559-a4aa-44721b80d107",
   "metadata": {},
   "outputs": [],
   "source": ["model = model.bind_tools(tools)"]
  },
  {
   "cell_type": "markdown",
   "id": "8e8b9211-93d0-4ad5-aa7a-9c09099c53ff",
   "metadata": {},
   "source": [
    "## Define the agent state\n",
    "\n",
    "The main type of graph in `langgraph` is the [StateGraph](https://langchain-ai.github.io/langgraph/reference/graphs/#langgraph.graph.StateGraph).\n",
    "This graph is parameterized by a state object that it passes around to each node.\n",
    "Each node then returns operations to update that state.\n",
    "These operations can either SET specific attributes on the state (e.g. overwrite the existing values) or ADD to the existing attribute.\n",
    "Whether to set or add is denoted by annotating the state object you construct the graph with.\n",
    "\n",
    "For this example, the state we will track will just be a list of messages.\n",
    "We want each node to just add messages to that list.\n",
    "Therefore, we will use a `TypedDict` with one key (`messages`) and annotate it so that the `messages` attribute is always added to.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ea793afa-2eab-4901-910d-6eed90cd6564",
   "metadata": {},
   "outputs": [],
   "source": ["import operator\nfrom typing import Annotated, Sequence, TypedDict\n\nfrom langchain_core.messages import BaseMessage\n\n\nclass AgentState(TypedDict):\n    messages: Annotated[Sequence[BaseMessage], operator.add]"]
  },
  {
   "cell_type": "markdown",
   "id": "e03c5094-9297-4d19-a04e-3eedc75cefb4",
   "metadata": {},
   "source": [
    "## Define the nodes\n",
    "\n",
    "We now need to define a few different nodes in our graph.\n",
    "In `langgraph`, a node can be either a function or a [runnable](https://python.langchain.com/v0.2/docs/concepts/#langchain-expression-language-lcel).\n",
    "There are two main nodes we need for this:\n",
    "\n",
    "1. The agent: responsible for deciding what (if any) actions to take.\n",
    "2. A function to invoke tools: if the agent decides to take an action, this node will then execute that action.\n",
    "\n",
    "We will also need to define some edges.\n",
    "Some of these edges may be conditional.\n",
    "The reason they are conditional is that based on the output of a node, one of several paths may be taken.\n",
    "The path that is taken is not known until that node is run (the LLM decides).\n",
    "\n",
    "1. Conditional Edge: after the agent is called, we should either:\n",
    "   a. If the agent said to take an action, then the function to invoke tools should be called\n",
    "   b. If the agent said that it was finished, then it should finish\n",
    "2. Normal Edge: after the tools are invoked, it should always go back to the agent to decide what to do next\n",
    "\n",
    "Let's define the nodes, as well as a function to decide how what conditional edge to take.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "03308b6b-de72-4cdc-b6c6-47e654df340e",
   "metadata": {},
   "outputs": [],
   "source": ["from langchain_core.messages import ToolMessage\n\nfrom langgraph.prebuilt import ToolInvocation"]
  },
  {
   "cell_type": "markdown",
   "id": "50bf356c-2dbd-4f66-8fa3-133e9c2e371e",
   "metadata": {},
   "source": [
    "**MODIFICATION**\n",
    "\n",
    "We change the `should_continue` function to check whether return_direct was set to True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "55e088b1-f3c8-4798-9ca8-5b0be961b49a",
   "metadata": {},
   "outputs": [],
   "source": ["# Define the function that determines whether to continue or not\ndef should_continue(state):\n    messages = state[\"messages\"]\n    last_message = messages[-1]\n    # If there is no function call, then we finish\n    if not last_message.tool_calls:\n        return \"end\"\n    # Otherwise if there is, we check if it's suppose to return direct\n    else:\n        arguments = last_message.tool_calls[0][\"args\"]\n        if arguments.get(\"return_direct\", False):\n            return \"final\"\n        else:\n            return \"continue\""]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "2b45da72-1afa-4cd7-9b7f-49a7c99cdb8a",
   "metadata": {},
   "outputs": [],
   "source": ["# Define the function that calls the model\ndef call_model(state):\n    messages = state[\"messages\"]\n    response = model.invoke(messages)\n    # We return a list, because this will get added to the existing list\n    return {\"messages\": [response]}"]
  },
  {
   "cell_type": "markdown",
   "id": "8535a36c-3ced-401e-98b5-ec1d1b434bbc",
   "metadata": {},
   "source": [
    "**MODIFICATION**\n",
    "\n",
    "We change the tool calling to get rid of the `return_direct` parameter (not used in the actual tool call)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "dd876f5d-88d6-4f93-b1d0-f2f0b6f4d991",
   "metadata": {},
   "outputs": [],
   "source": ["# Define the function to execute tools\ndef call_tool(state):\n    messages = state[\"messages\"]\n    # Based on the continue condition\n    # we know the last message involves a function call\n    last_message = messages[-1]\n    # We construct an ToolInvocation from the function_call\n    tool_call = last_message.tool_calls[0]\n    tool_name = tool_call[\"name\"]\n    arguments = tool_call[\"args\"]\n    if tool_name == \"tavily_search_results_json\":\n        if \"return_direct\" in arguments:\n            del arguments[\"return_direct\"]\n    action = ToolInvocation(\n        tool=tool_name,\n        tool_input=arguments,\n    )\n    # We call the tool_executor and get back a response\n    response = tool_executor.invoke(action)\n    # We use the response to create a ToolMessage\n    tool_message = ToolMessage(\n        content=str(response), name=action.tool, tool_call_id=tool_call[\"id\"]\n    )\n    # We return a list, because this will get added to the existing list\n    return {\"messages\": [tool_message]}"]
  },
  {
   "cell_type": "markdown",
   "id": "ffd6e892-946c-4899-8cc0-7c9291c1f73b",
   "metadata": {},
   "source": [
    "## Define the graph\n",
    "\n",
    "We can now put it all together and define the graph!\n",
    "\n",
    "**MODIFICATION**\n",
    "\n",
    "We add a separate node for any tool call where `return_direct=True`. The reason this is needed is that after this node we want to end, while after other tool calls we want to go back to the LLM. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "813ae66c-3b58-4283-a02a-36da72a2ab90",
   "metadata": {},
   "outputs": [],
   "source": ["from langgraph.graph import END, StateGraph, START\n\n# Define a new graph\nworkflow = StateGraph(AgentState)\n\n# Define the two nodes we will cycle between\nworkflow.add_node(\"agent\", call_model)\nworkflow.add_node(\"action\", call_tool)\nworkflow.add_node(\"final\", call_tool)\n\n# Set the entrypoint as `agent`\n# This means that this node is the first one called\nworkflow.add_edge(START, \"agent\")\n\n# We now add a conditional edge\nworkflow.add_conditional_edges(\n    # First, we define the start node. We use `agent`.\n    # This means these are the edges taken after the `agent` node is called.\n    \"agent\",\n    # Next, we pass in the function that will determine which node is called next.\n    should_continue,\n    # Finally we pass in a mapping.\n    # The keys are strings, and the values are other nodes.\n    # END is a special node marking that the graph should finish.\n    # What will happen is we will call `should_continue`, and then the output of that\n    # will be matched against the keys in this mapping.\n    # Based on which one it matches, that node will then be called.\n    {\n        # If `tools`, then we call the tool node.\n        \"continue\": \"action\",\n        # Final call\n        \"final\": \"final\",\n        # Otherwise we finish.\n        \"end\": END,\n    },\n)\n\n# We now add a normal edge from `tools` to `agent`.\n# This means that after `tools` is called, `agent` node is called next.\nworkflow.add_edge(\"action\", \"agent\")\nworkflow.add_edge(\"final\", END)\n\n# Finally, we compile it!\n# This compiles it into a LangChain Runnable,\n# meaning you can use it as you would any other runnable\napp = workflow.compile()"]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "05b43439",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/4gHYSUNDX1BST0ZJTEUAAQEAAAHIAAAAAAQwAABtbnRyUkdCIFhZWiAH4AABAAEAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAACRyWFlaAAABFAAAABRnWFlaAAABKAAAABRiWFlaAAABPAAAABR3dHB0AAABUAAAABRyVFJDAAABZAAAAChnVFJDAAABZAAAAChiVFJDAAABZAAAAChjcHJ0AAABjAAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAAgAAAAcAHMAUgBHAEJYWVogAAAAAAAAb6IAADj1AAADkFhZWiAAAAAAAABimQAAt4UAABjaWFlaIAAAAAAAACSgAAAPhAAAts9YWVogAAAAAAAA9tYAAQAAAADTLXBhcmEAAAAAAAQAAAACZmYAAPKnAAANWQAAE9AAAApbAAAAAAAAAABtbHVjAAAAAAAAAAEAAAAMZW5VUwAAACAAAAAcAEcAbwBvAGcAbABlACAASQBuAGMALgAgADIAMAAxADb/2wBDAAMCAgMCA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J2fdhEWb96nFPZDPpZPzk96nFPZDPpZPzk0C10k/LH1HEk9J2fdgJaeKfXaxMk13c7QdLr9H0v9Wh+jCkfvU4p7IZ9LJ+cnvU4p7IZ9LJ+cmgWukn5Y+o4knpOz7o/FTQwEmOJkZPeWNAXLGP3zKf8UVH/mgWe96nFPZDPpZPzlkLHg9jxusfV223x0tS+MxGUOc48hIJHUnpsD+5bFjJ7eT158VzOqY2YbYw3y28k4MnJr0Xc/HDHm9XvZ1ERWu8IiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiIP/9k=",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": ["from IPython.display import Image, display\n\ntry:\n    display(Image(app.get_graph(xray=True).draw_mermaid_png()))\nexcept Exception:\n    # This requires some extra dependencies and is optional\n    pass"]
  },
  {
   "cell_type": "markdown",
   "id": "547c3931-3dae-4281-ad4e-4b51305594d4",
   "metadata": {},
   "source": [
    "## Use it!\n",
    "\n",
    "We can now use it!\n",
    "This now exposes the [same interface](https://python.langchain.com/v0.2/docs/concepts/#langchain-expression-language-lcel) as all other LangChain runnables."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "f544977e-31f7-41f0-88c4-ec9c27b8cecb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Output from node 'agent':\n",
      "---\n",
      "{'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_zUSn183pDK7QjqaJLkznOWv9', 'function': {'arguments': '{\"query\":\"weather in San Francisco\"}', 'name': 'tavily_search_results_json'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_calls'}, id='run-1c45e1ae-6b0d-40df-9727-e76b391caa03-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'weather in San Francisco'}, 'id': 'call_zUSn183pDK7QjqaJLkznOWv9'}])]}\n",
      "\n",
      "---\n",
      "\n",
      "Output from node 'action':\n",
      "---\n",
      "{'messages': [ToolMessage(content='[{\\'url\\': \\'https://www.weatherapi.com/\\', \\'content\\': \"{\\'location\\': {\\'name\\': \\'San Francisco\\', \\'region\\': \\'California\\', \\'country\\': \\'United States of America\\', \\'lat\\': 37.78, \\'lon\\': -122.42, \\'tz_id\\': \\'America/Los_Angeles\\', \\'localtime_epoch\\': 1714808273, \\'localtime\\': \\'2024-05-04 0:37\\'}, \\'current\\': {\\'last_updated_epoch\\': 1714807800, \\'last_updated\\': \\'2024-05-04 00:30\\', \\'temp_c\\': 12.8, \\'temp_f\\': 55.0, \\'is_day\\': 0, \\'condition\\': {\\'text\\': \\'Overcast\\', \\'icon\\': \\'//cdn.weatherapi.com/weather/64x64/night/122.png\\', \\'code\\': 1009}, \\'wind_mph\\': 11.9, \\'wind_kph\\': 19.1, \\'wind_degree\\': 240, \\'wind_dir\\': \\'WSW\\', \\'pressure_mb\\': 1013.0, \\'pressure_in\\': 29.9, \\'precip_mm\\': 0.0, \\'precip_in\\': 0.0, \\'humidity\\': 96, \\'cloud\\': 100, \\'feelslike_c\\': 11.4, \\'feelslike_f\\': 52.4, \\'vis_km\\': 16.0, \\'vis_miles\\': 9.0, \\'uv\\': 1.0, \\'gust_mph\\': 14.9, \\'gust_kph\\': 23.9}}\"}]', name='tavily_search_results_json', tool_call_id='call_zUSn183pDK7QjqaJLkznOWv9')]}\n",
      "\n",
      "---\n",
      "\n",
      "Output from node 'agent':\n",
      "---\n",
      "{'messages': [AIMessage(content='The current weather in San Francisco is as follows:\\n- Temperature: 55.0°F (12.8°C)\\n- Condition: Overcast\\n- Wind: 11.9 mph from WSW\\n- Humidity: 96%\\n- Cloud Cover: 100%\\n- Feels like: 52.4°F (11.4°C)\\n- Visibility: 9.0 miles\\n\\nFor more details, you can visit [Weather API](https://www.weatherapi.com/).', response_metadata={'finish_reason': 'stop'}, id='run-ba632ae4-5910-48c8-a550-889e59608895-0')]}\n",
      "\n",
      "---\n",
      "\n"
     ]
    }
   ],
   "source": ["from langchain_core.messages import HumanMessage\n\ninputs = {\"messages\": [HumanMessage(content=\"what is the weather in sf\")]}\nfor output in app.stream(inputs):\n    # stream() yields dictionaries with output keyed by node name\n    for key, value in output.items():\n        print(f\"Output from node '{key}':\")\n        print(\"---\")\n        print(value)\n    print(\"\\n---\\n\")"]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "08ae8246-11d5-40e1-8567-361e5bef8917",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Output from node 'agent':\n",
      "---\n",
      "{'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_Xks2mun3a2rITryq3Y7EMMOU', 'function': {'arguments': '{\"query\":\"weather in San Francisco\",\"return_direct\":true}', 'name': 'tavily_search_results_json'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_calls'}, id='run-890b9e87-b203-4314-acf0-a09ff18dcb6f-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'weather in San Francisco', 'return_direct': True}, 'id': 'call_Xks2mun3a2rITryq3Y7EMMOU'}])]}\n",
      "\n",
      "---\n",
      "\n",
      "Output from node 'final':\n",
      "---\n",
      "{'messages': [ToolMessage(content='[{\\'url\\': \\'https://www.weatherapi.com/\\', \\'content\\': \"{\\'location\\': {\\'name\\': \\'San Francisco\\', \\'region\\': \\'California\\', \\'country\\': \\'United States of America\\', \\'lat\\': 37.78, \\'lon\\': -122.42, \\'tz_id\\': \\'America/Los_Angeles\\', \\'localtime_epoch\\': 1714808273, \\'localtime\\': \\'2024-05-04 0:37\\'}, \\'current\\': {\\'last_updated_epoch\\': 1714807800, \\'last_updated\\': \\'2024-05-04 00:30\\', \\'temp_c\\': 12.8, \\'temp_f\\': 55.0, \\'is_day\\': 0, \\'condition\\': {\\'text\\': \\'Overcast\\', \\'icon\\': \\'//cdn.weatherapi.com/weather/64x64/night/122.png\\', \\'code\\': 1009}, \\'wind_mph\\': 11.9, \\'wind_kph\\': 19.1, \\'wind_degree\\': 240, \\'wind_dir\\': \\'WSW\\', \\'pressure_mb\\': 1013.0, \\'pressure_in\\': 29.9, \\'precip_mm\\': 0.0, \\'precip_in\\': 0.0, \\'humidity\\': 96, \\'cloud\\': 100, \\'feelslike_c\\': 11.4, \\'feelslike_f\\': 52.4, \\'vis_km\\': 16.0, \\'vis_miles\\': 9.0, \\'uv\\': 1.0, \\'gust_mph\\': 14.9, \\'gust_kph\\': 23.9}}\"}]', name='tavily_search_results_json', tool_call_id='call_Xks2mun3a2rITryq3Y7EMMOU')]}\n",
      "\n",
      "---\n",
      "\n"
     ]
    }
   ],
   "source": ["from langchain_core.messages import HumanMessage\n\ninputs = {\n    \"messages\": [\n        HumanMessage(\n            content=\"what is the weather in sf? return this result directly by setting return_direct = True\"\n        )\n    ]\n}\nfor output in app.stream(inputs):\n    # stream() yields dictionaries with output keyed by node name\n    for key, value in output.items():\n        print(f\"Output from node '{key}':\")\n        print(\"---\")\n        print(value)\n    print(\"\\n---\\n\")"]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "49ccc134-4abe-4982-8ecd-d70fc56a4d2d",
   "metadata": {},
   "outputs": [],
   "source": [""]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
